<?php

/**
 * WK 首页文件
 * ============================================================================
 * * 版权所有 2005-2012 QQ 80342014，并保留所有权利。
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: liubo $
 * $Id: index.php 17217 2011-01-19 06:29:08Z liubo $
*/

define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');


// $userset = get_user_set($_SESSION['user_id']);
// if($userset['wxid']){
	// wx_msg($userset['wxid'],30);
// }


// die('---');





assign_template();

$position = assign_ur_here();
$smarty->assign('page_title',      $position['title']);    // 页面标题
$smarty->assign('ur_here',         $position['ur_here']);  // 当前位置
include_once(ROOT_PATH .'includes/lib_clips.php');
if ($rank = get_rank_info())
{
	$smarty->assign('rank_name', sprintf($_LANG['your_level'], $rank['rank_name']));
	if (!empty($rank['next_rank_name']))
	{
		$smarty->assign('next_rank_name', sprintf($_LANG['next_level'], $rank['next_rank'] ,$rank['next_rank_name']));
	}
}
$smarty->assign('action',        'default');
$smarty->assign('acts',        'index');
$smarty->assign('page_title',        '云端联合养殖平台');
$smarty->assign('info',        get_user_default($user_id));
$smarty->assign('user_notice', $_CFG['user_notice']);
$smarty->assign('prompt',      get_user_prompt($user_id));



/* 获取养了多少羊 */
$this_count  =  get_this_count($_SESSION['user_id']);
$smarty->assign('this_count',        $this_count);
$smarty->assign('user_id',        $_SESSION['user_id']);

/* 获取 最新的一条羊数据 */
$yang = get_yang();
$smarty->assign('yang',        $yang); 

/* 获取当月应该获取提成 */
$this_money = get_this_money($_SESSION['user_id']);
$smarty->assign('this_money',        $this_money); 
 


// 获取公告  分类id是 5  只取最新的一条
$get_top_one = get_top_one(5);
$smarty->assign('get_top_one',      $get_top_one);

// 天气
$baiduak='m0hGtNFa1VuEbmL36x1X2KGL';//百度地图api的密钥
$wea=new getWeather($baiduak);
$tianqi = $wea->weatherInfo('洛阳');
$Weather = array();
//小雨 19.5℃

$status =  $tianqi['Weather']['status1'] . ' '. $tianqi['Weather']['temperature1'];
if(empty($tianqi['Weather']['status1']) || empty($tianqi['Weather']['temperature1'])){
	$status =  $tianqi['Weather']['status2'] . ' '. $tianqi['Weather']['temperature2'];
}

$Weather['tianqi'] =  $status.'℃';
$Weather['figure'] =    !empty($tianqi['Weather']['figure1']) ? $tianqi['Weather']['figure1']: $tianqi['Weather']['figure2'];
 
$smarty->assign('Weather',      $Weather);
 

$smarty->display('user_default.dwt');

/*----------------------------------------------*/
//--  wk  函数
/*-----------------------------------------------*/
/**
 * 获取公告最新的一条 显示在首页
 *
 * @param   integer $num
 * @param   integer $start
 *
 * @return  array
 */
function get_top_one($cat_id = 5){
	$arr = array();
	if(!$cat_id){
		return $arr;
	}
	$sql = "select * from ".$GLOBALS['ecs']->table('article'). " where cat_id = '$cat_id' and is_open = 1 order by add_time desc";
	$arr = $GLOBALS['db']->getRow($sql);
	if($arr){
		
		$arr['url'] = build_uri('article', array('aid'=>$arr['article_id']), $arr['title']);
	}
	return $arr;
}



?>